package com.suyuan.controller.shop.admin;


import com.suyuan.entity.EmployeeInfo;
import com.suyuan.service.EmployeeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


/**
 * 商城后台
 */
@Controller
@RequestMapping(value = "/shop/admin")
public class Index2Controller {

    @Resource
    private EmployeeService employeeService;

    /**
     * 跳转到商城后台登录页面
     * @return
     */
    @RequestMapping("toLogin")
    public String toLogin(){
        return "shopLogin";
    }


    /**
     * 商城后台登录方法
     * @param employeeInfo2
     * @return
     */
    @RequestMapping("login")
    public String login(EmployeeInfo employeeInfo2, HttpServletRequest request) {
        EmployeeInfo activeEmployeeInfo = employeeService.checkEmployeeInfo(employeeInfo2);
        if(activeEmployeeInfo != null){
            request.getSession().setAttribute("activeEmployeeInfo",activeEmployeeInfo);
            return "shopIndex";
        }
        return "shopLogin";
    }

	//用户退出
	@RequestMapping("/logout")
	public String logout(HttpSession session){
		//session失效
		session.invalidate();
		//重定向到商品查询页面
		return "shopLogin";

	}

    /**
     * 首页
     * @return
     */
	@RequestMapping(value = "index")
	public String index(){
	    return "shopIndex";
    }

}
